package br.unicamp.ic.lsd;

import javax.jws.WebService;

import br.unicamp.ic.lsd.exceptions.HException;
import br.unicamp.ic.lsd.exceptions.LException;
import br.unicamp.ic.lsd.exceptions.MException;

@WebService(endpointInterface = "br.unicamp.ic.lsd.ServiceFour", serviceName = "webserviceFour")
public class ServiceFourImpl implements ServiceFour {
    private static boolean HExceptionThrow = false;
    private static boolean LExceptionThrow = false;
    private static boolean MExceptionThrow = false;
    private static long timeoutMethodOne = 0;
    private static long timeoutMethodTwo = 0;
    private static long timeoutMethodThree = 0;
    
    @Override
    public String methodOneWSFour(int k) throws HException {
	if(HExceptionThrow)
	    k=1;
	
	try {
	    Thread.sleep(timeoutMethodOne);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
	
	switch (k) {
	case 0:
	    return "methodOneWSFour executado com sucesso";
	case 1:
	    throw new HException("Falha do metodo methodOneWSFour");
	}
	return "Algum erro ocorreu no metodo methodOneWSFour";
    }

    @Override
    public String methodTwoWSFour(int k) throws LException {
	if(LExceptionThrow)
	    k=1;
	
	try {
	    Thread.sleep(timeoutMethodTwo);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
	
	switch (k) {
	case 0:
	    return "methodTwoWSFour executado com sucesso";
	case 1:
	    throw new LException("Falha do metodo methodTwoWSFour");
	}
	return "Algum erro ocorreu no metodo methodTwoWSFour";
    }

    @Override
    public String methodThreeWSFour(int k) throws MException {
	if(MExceptionThrow)
	    k=1;
	
	try {
	    Thread.sleep(timeoutMethodThree);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
	
	switch (k) {
	case 0:
	    return "methodThreeWSFour executado com sucesso";
	case 1:
	    throw new MException("Falha do metodo methodThreeWSFour");
	}
	return "Algum erro ocorreu no metodo methodThreeWSFour";
    }

    @Override
    public boolean isHExceptionThrow() {
        return HExceptionThrow;
    }

    @Override
    public void setHExceptionThrow(boolean hExceptionThrow) {
        HExceptionThrow = hExceptionThrow;
    }

    @Override
    public boolean isLExceptionThrow() {
        return LExceptionThrow;
    }

    @Override
    public void setLExceptionThrow(boolean lExceptionThrow) {
        LExceptionThrow = lExceptionThrow;
    }

    @Override
    public boolean isMExceptionThrow() {
        return MExceptionThrow;
    }

    @Override
    public void setMExceptionThrow(boolean mExceptionThrow) {
        MExceptionThrow = mExceptionThrow;
    }
    
    @Override
    public long getTimeoutMethodOne() {
	return timeoutMethodOne;
    }

    @Override
    public void setTimeoutMethodOne(long timeoutMethodOne) {
	ServiceFourImpl.timeoutMethodOne = timeoutMethodOne;
    }

    @Override
    public long getTimeoutMethodTwo() {
	return timeoutMethodTwo;
    }

    @Override
    public void setTimeoutMethodTwo(long timeoutMethodTwo) {
	ServiceFourImpl.timeoutMethodTwo = timeoutMethodTwo;
    }

    @Override
    public long getTimeoutMethodThree() {
	return timeoutMethodThree;
    }

    @Override
    public void setTimeoutMethodThree(long timeoutMethodThree) {
	ServiceFourImpl.timeoutMethodThree = timeoutMethodThree;
    }
}
